import pandas as pd

import TimeUtil
import util
from Input import get_statistic_path

if __name__ == '__main__':
    import openpyxl

    value = []
    # 月份
    m = 3
    # 日期
    d = 5
    a = 231
    b = 232
    date = TimeUtil.parse(f'2025-03-{util.get_day(d)}')
    workbook = openpyxl.load_workbook(f"D:\\中断输入\\输出\\{m}.{d}日单用户中断时长各分公司指标.xlsx", data_only=True)
    sheet = workbook['单用户中断时长']

    value.append([sheet[f'B{i}'].value for i in range(a, a + 16)])
    sheet = workbook['中断用户平均修复时长']
    value.append([sheet[f'B{i}'].value for i in range(a, a + 16)])
    sheet = workbook['用户平均中断率']
    value.append([sheet[f'B{i}'].value for i in range(b, b + 16)])
    sheet = workbook['用户平均中断次数']
    value.append([sheet[f'B{i}'].value for i in range(b, b + 16)])
    value.append([sheet[f'D{i}'].value / d for i in range(b, b + 16)])

    workbook = openpyxl.load_workbook("D:\\中断输入\\新建文件夹\\过程表\\单用户中断时长.xlsx")
    sheet = workbook['统计']

    # 外层循环遍历每一行，同时获取行索引
    for row_index, row in enumerate(value):
        # 内层循环遍历当前行的每个元素，同时获取列索引
        for col_index, element in enumerate(row):
            sheet.cell(row=col_index + 4, column=row_index + 2).value = element

    df = pd.read_csv(get_statistic_path(date))
    for i in range(4, 20):
        sheet.cell(row=i, column=10).value = df['fttr用户数_x'].iloc[i - 4]
        sheet.cell(row=i, column=11).value = df['fttr中断时长总和_x'].iloc[i - 4] / 60 / d

    sheet['A2'].value = f'截至{m}.{d}日'
    sheet['I2'].value = f'FTTR指标情况（截止{m}.{d}号）'
    workbook.save("D:\\中断输入\\新建文件夹\\过程表\\单用户中断时长（250307).xlsx")
